package com.upcode.weighing.admin.controller.sms;


import cn.jpush.api.push.PushResult;
import com.upcode.weighing.base.controller.BaseController;
import com.upcode.weighing.jpush.JpushUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author alex
 * @since 2019-03-10
 */


@RestController
@RequestMapping("/jpush")
@Api(value = "/jpush", description = "微服务测试接口", produces = MediaType.ALL_VALUE)
public class JpushController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(JpushController.class);

    @Autowired
    private JpushUtil jpushUtil;

    @PostMapping("/sendToAliasList")
    public int test(@RequestBody Map map){
        try {
            List<String> ali = (List<String>) map.get("ali");
            String notificationTitle = map.get("notificationTitle").toString();
            String msgTitle= map.get("msgTitle").toString();
            String msgContent= map.get("msgContent").toString();
            logger.info("##### getSendToAliasListData={}",map.toString());
            PushResult pr = jpushUtil.sendToAliasList(ali,notificationTitle,msgTitle,msgContent,"无");
            logger.info("##### jpushUtil  getSendToAliasListData  PushResult={}",pr);
        }catch (Exception e){
            return 0;
        }
        return 2;
    }


}
